package lab6.systemCustom;

import java.util.Observable;
import java.util.Observer;

public class EventBus {

	public static class Event extends Observable {

		public void getDirty() {
			super.setChanged();
		}
	}

	public static final int EV_SHOW = 0;

	public static final int EV_LIST_ALL_STUDENTS = 1;

	public static final int EV_LIST_ALL_COURSES = 2;

	public static final int EV_LIST_STUDENTS_REGISTERED = 3;

	public static final int EV_LIST_COURSES_REGISTERED = 4;

	public static final int EV_LIST_COURSES_COMPLETED = 5;

	public static final int EV_REGISTER_STUDENT = 6;

	/**
	 * Evenimentul pentru verificarea supraslicitarii unui curs.
	 */
	public static final int EV_CHECK_COURSE_OVERDEMAND = 10;

	/**
	 * Evenimentul pentru cererea verificarii conflictelor unui curs.
	 */
	public static final int EV_CHECK_COURSE_CONFLICT = 11;

	/**
	 * Evenimentul pentru raspunsul de la verificarea conflictelor unui curs.
	 */
	public static final int EV_RESPONSE_TO_COURSE_CONFLICT_CHECK = 12;

	/**
	 * Evenimentul pentru esecul inscrierii unui student la un curs.
	 */
	public static final int EV_STUDENT_REGISTRATION_FAIL = 13;

	public static final int MAX_NUM_EVENTS = 100;

	protected static Event[] aEvent = new Event[MAX_NUM_EVENTS];

	public static void initialize() {
		for (int i = 0; i < MAX_NUM_EVENTS; i++) {
			aEvent[i] = new Event();
		}
	}

	public static void subscribeTo(int iEventCode, Observer objSubscriber) {
		aEvent[iEventCode].addObserver(objSubscriber);
	}

	public static void announce(int iEventCode, String sEventParam) {
		aEvent[iEventCode].getDirty();
		aEvent[iEventCode].notifyObservers(sEventParam);
	}

}